package com.inhim.pjhim.adapter.provider;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RadioButton;

import com.inhim.pjhim.R;
import com.inhim.pjhim.utils.UIUtils;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.holder.BaseViewHolder;


public class DialogSelectAdapter extends RecyclerArrayAdapter<String> {

    private Context mContext;
    PersonViewHolder viewHolder;
    private int mPosition=-1;

    public DialogSelectAdapter(Context context) {
        super(context);
        this.mContext=context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        View mView = null;
        if (mView == null) {
            mView = LayoutInflater.from(mContext).inflate(R.layout.item_dialog_select, null);
            viewHolder = new PersonViewHolder(mView,viewType);
        } else {
            viewHolder = (PersonViewHolder) mView.getTag();
        }
        return viewHolder;
    }

    public void setPosition(int position) {
        this.mPosition=position;
    }

    public class PersonViewHolder extends BaseViewHolder<String> {
        private RadioButton radio;
        private LinearLayout linearLayout;
        private int showPosition;
        public PersonViewHolder(View itemView,int position) {
            super(itemView);
            radio = getView(R.id.radio);
            linearLayout=getView(R.id.lin);
            addOnClickListener(R.id.radio);
            showPosition=position;
            LinearLayout.LayoutParams Params   =  (LinearLayout.LayoutParams)linearLayout.getLayoutParams();
            Params.width = UIUtils.getAppWidth(mContext);
            linearLayout.setLayoutParams(Params);
        }

        @Override
        public void setData(String data) {
            super.setData(data);
            radio.setText(data);
            if(mPosition == showPosition){
                radio.setChecked(true);
            }else{
                radio.setChecked(false);
            }
        }

    }

}
